﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GpCommon.Helpers;
using GPSpeedView.Models;

namespace GPSpeedView.GPHelpers
{
    public class GpAnalysisHelper
    {
        //                                               涨停数据                 未涨停数据
        // 日期   涨停树   占比   未涨停   占比     0～30   30～50  50～100  100～300  300～1000   1000以上

        public static void ExportTopPlan1ToExcel(string fileName, List<TopPlan1Entity> entities)
        {
            if (string.IsNullOrEmpty(fileName) || entities.Count <= 0)
                return;
            using (FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            {
                var workbook = ExcelExportUtils.OpenWorkbook(file, fileName);
                var sheet = workbook.GetSheetAt(0);
                //var sheet = ExcelExportUtils.CreateSheet("首板涨停", workbook);

                var cellStyle = ExcelExportUtils.CreateItemCellStyle(workbook);
                var rowIndex = 3;
                for (int i = 0; i < entities.Count; i++)
                {
                    var excelRow = sheet.CreateRow(rowIndex);

                    ExcelExportUtils.CreateCell(excelRow, 0, entities[i].Time.Date.ToString(), cellStyle);
                    ExcelExportUtils.CreateCell(excelRow, 1, entities[i].TopCount.ToString(), cellStyle);
                    ExcelExportUtils.CreateCell(excelRow, 2, (entities[i].TopCount / (entities[i].TopCount + entities[i].NoTopCount + 0.0)).ToString("F2"), cellStyle);
                    ExcelExportUtils.CreateCell(excelRow, 3, entities[i].NoTopCount.ToString(), cellStyle);
                    ExcelExportUtils.CreateCell(excelRow, 4, (entities[i].NoTopCount / (entities[i].TopCount + entities[i].NoTopCount)).ToString("F2"), cellStyle);

                    ExcelExportUtils.CreateCell(excelRow, 5, (entities[i].Top0_30 / (entities[i].TopCount + 0.0)).ToString("F2"), cellStyle);
                    ExcelExportUtils.CreateCell(excelRow, 6, (entities[i].Top30_50 / (entities[i].TopCount + 0.0)).ToString("F2"), cellStyle);
                    ExcelExportUtils.CreateCell(excelRow, 7, (entities[i].Top50_100 / (entities[i].TopCount + 0.0)).ToString("F2"), cellStyle);
                    ExcelExportUtils.CreateCell(excelRow, 8, (entities[i].Top100_300 / (entities[i].TopCount + 0.0)).ToString("F2"), cellStyle);
                    ExcelExportUtils.CreateCell(excelRow, 9, (entities[i].Top300_1000 / (entities[i].TopCount + 0.0)).ToString("F2"), cellStyle);
                    ExcelExportUtils.CreateCell(excelRow, 10, (entities[i].Top1000 / (entities[i].TopCount + 0.0)).ToString("F2"), cellStyle);

                    ExcelExportUtils.CreateCell(excelRow, 11, (entities[i].NoTop0_30 / (entities[i].NoTopCount + 0.0)).ToString("F2"), cellStyle);
                    ExcelExportUtils.CreateCell(excelRow, 12, (entities[i].NoTop30_50 / (entities[i].NoTopCount + 0.0)).ToString("F2"), cellStyle);
                    ExcelExportUtils.CreateCell(excelRow, 13, (entities[i].NoTop50_100 / (entities[i].NoTopCount + 0.0)).ToString("F2"), cellStyle);
                    ExcelExportUtils.CreateCell(excelRow, 14, (entities[i].NoTop100_300 / (entities[i].NoTopCount + 0.0)).ToString("F2"), cellStyle);
                    ExcelExportUtils.CreateCell(excelRow, 15, (entities[i].NoTop300_1000 / (entities[i].NoTopCount + 0.0)).ToString("F2"), cellStyle);
                    ExcelExportUtils.CreateCell(excelRow, 16, (entities[i].NoTop1000 / (entities[i].NoTopCount + 0.0)).ToString("F2"), cellStyle);
                    rowIndex++;
                }

                ExcelExportUtils.WriteToFile(workbook, fileName);
            }


        }
    }
}
